<template>
  <tl-sub-page :render="render" :visible.sync="visible" :title="title" v-dialogDrag width="1100px" top="10px" class="tl-dialog" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="120px" :disabled="disableEditSubmit || stateApproval">
      <el-row>
        <el-col :span="12">
          <el-form-item label="维修类别" prop="boardroomid" :rules="rules.validateRequire"> </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="维修地址" prop="address" :rules="rules.validateRequire">
            <el-input v-model="model.address" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="维修内容" prop="applycontent" :rules="rules.validateRequire">
            <el-input v-model="model.applycontent" type="textarea" :rows="2" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="审批流程" prop="flowid">
            <el-select v-model="model.flowid" :disabled="true">
              <el-option v-for="item in codeModel.flowList" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="telephone" :rules="rules.validateRequire">
            <el-input v-model="model.telephone" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="申请人" prop="username">
            <el-input v-model="model.username" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="工号" prop="usercode">
            <el-input v-model="model.usercode" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="公司" prop="orgcode">
            <el-input v-model="model.disporgcode" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所属部门" prop="deptcode">
            <el-input v-model="model.deptname" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <tl-approval-history ref="history" sourceType="ToaBoardroomApply" :sourceId="model.id" />
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="!disableEditSubmit" :disabled="disableSave"><svg-icon icon-class="save" />保存</el-button>
      <el-button type="primary" @click="doSubmitApproval" :loading="submitLoading" v-if="!disableEditSubmit" :disabled="disableApproval"><svg-icon icon-class="send" />提交审批</el-button>
      <tl-attachment sourceType="ToaParkMaintenance" :sourceId="model.id" :disabled="disableAttachment"></tl-attachment>
      <el-button type="primary" @click="$refs.history.visible = true" :disabled="disableApprovalHistory"><svg-icon icon-class="list" />审批历史</el-button>
      <el-button type="primary" @click="doDelApproval" :loading="delApprovalLoading" v-if="!disableEditSubmit" :disabled="disableDelApproval"><svg-icon icon-class="undo" />取消审批</el-button>
    </div>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { queryDataCode } from '@tapui/api/dataCode'
import { mixin_approval_edit } from '@tapui/mixins/mixin_approval_edit'
import { getInfo } from '@tapui/api/login'
import { putAction, getAction, postAction } from '@tapui/utils/http'
/** 子组件 */
import tlRefItem from '../boardroomItem/ref'
export default {
  components: { tlRefItem },
  mixins: [mixin_approval_edit],
  data() {
    return {
      moduleTitle: '维修申请',
      url: {
        add: '/toa/parkMaintenance/insert',
        edit: '/toa/parkMaintenance/update',
        load: '/toa/parkMaintenance/load',
        submit: '/toa/boardrooparkMaintenancemApply/submit',
        delApproval: '/toa/parkMaintenance/delApproval',
        queryCodeList: '/toa/parkMaintenance/dataCodeList'
      },
      displayMore: false
    }
  },
  methods: {
    beforeSubmit() {
      return true
    },
    assignDefaultValue() {
      if (this.isAdd) {
        if (this.codeModel.flowList.length > 0) this.$set(this.model, 'flowid', parseInt(this.codeModel.flowList[0].id))
        this.$set(this.model, 'orgcode', this.org.code)
        this.$set(this.model, 'disporgcode', this.org.name)
        this.$set(this.model, 'deptcode', this.dept.code)
        this.$set(this.model, 'deptname', this.dept.fullname)
        this.$set(this.model, 'usercode', this.user.code)
        this.$set(this.model, 'username', this.user.name)
        this.$set(this.model, 'telephone', this.user.mobile)
        this.$set(this.model, 'hostusercode', this.user.code)
        this.$set(this.model, 'disphostusercode', this.user.name)
      }
    }
  }
}
</script>

<style scoped>
.red {
  color: red;
}
</style>
